<?php

namespace app\xwam\controller;

/**
 * 支付方式 控制器
 *
 * @since 1.0 <2017-3-27> SoChishun <14507247@qq.com> Added.
 */
class PaymentController extends AppbaseController {

    // 2017-3-24
    public function edit() {
        $where = array('name' => 'QQ');
        $mOauth = new \app\xwam\model\OauthModel();
        $data = $mOauth->where($where)->find();
        if (!$data) {
            $mOauth->add($where);
            $data = $mOauth->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    public function wechat() {
        $where = array('name' => 'WECHAT');
        $mOauth = new \app\xwam\model\OauthModel();
        $data = $mOauth->where($where)->find();
        if (!$data) {
            $mOauth->add($where);
            $data = $mOauth->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    public function weibo() {
        $where = array('name' => 'WEIBO');
        $mOauth = new \app\xwam\model\OauthModel();
        $data = $mOauth->where($where)->find();
        if (!$data) {
            $mOauth->add($where);
            $data = $mOauth->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    public function editSave() {
        $mOauth = new \app\xwam\model\OauthModel();
        $result = $mOauth->saveConf();
        $this->dialogJump($result['status'], $result['info']);
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = ACTION_NAME;
        }
        $data = array(
            'edit' => array('title' => '微信支付', 'url' => 'edit', 'active' => ''),
            'wechat' => array('title' => '支付宝即时到帐', 'url' => 'wechat', 'active' => ''),
            //'weibo' => array('title' => '支付宝担保交易', 'url' => 'weibo', 'active' => ''),
            'weibo' => array('title' => '贝宝Paypal', 'url' => 'weibo', 'active' => ''),
            'weibo' => array('title' => '余额支付', 'url' => 'weibo', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
